import { objectOmit } from '@vueuse/core'
import { type IBefore, defaultWithIBefore } from './before'
import type { IDict } from './dict'

export const defaultWithIBeforeCase: IBeforeCase = {
  id: -1,
  moduleId: -1,
  name: '',
  cyclesNum: 1,
  browser: 'CHROME',
  headArguments: 'HEAD',
  status: '未执行',
  description: '',
  level: 'p0',
  beforeCaseFlag:"YES",
  isSyncSession: true,
  isSyncCookie: true,
  createAccountId: 0,
  updateAccountId: 0,
  gmtCreate: '',
  gmtModified: '',
  stepList: [],
}

export interface IBeforeCase {
  id: number
  moduleId: number
  name: string
  cyclesNum: number
  browser: string
  headArguments: string
  description: string
  level: string
  beforeCaseFlag: string
  status: string
  isSyncSession: boolean
  isSyncCookie: boolean
  createAccountId: number
  updateAccountId: number
  gmtCreate: string
  gmtModified: string
  stepList: IBeforeCaseStep[]
}

export const defaultWithIBeforeCaseStep: IBeforeCaseStep = {
  ...objectOmit(defaultWithIBefore, ['moduleId']),
  caseId: 0,
  num: 0,
  assertion: '[]',
  relation: '[]',
  locationType: '',
  locationExpress: ''
}

export type IBeforeCaseStep = Omit<IBefore, 'moduleId'> & {
  caseId: number
  num: number
  assertion: string
  relation: string,
  locationType: string
  locationExpress: string
}


export const defaultWithIBeforeCaseStepAssertion: IBeforeCaseStepAssertion = {
  from: 'response_code',
  type: 'regexp',
  action: 'equal',
  express: '',
  value: '',
}

export interface IBeforeCaseStepAssertion {
  from: 'response_code' | 'response_header' | 'response_body'
  type: 'regexp' | 'jsonpath'
  action:
    | 'contain'
    | 'not_contain'
    | 'equal'
    | 'not_equal'
    | 'great_then'
    | 'less_then'
  express: string
  value: string
}

export const defaultWithIBeforeCaseStepRelation: IBeforeCaseStepRelation = {
  from: 'request_header',
  type: 'regexp',
  express: '',
  name: '',
}

export interface IBeforeCaseStepRelation {
  from:
    | 'request_header'
    | 'request_body'
    | 'request_query'
    | 'response_header'
    | 'response_body'
  type: 'regexp' | 'jsonpath'
  express: string
  name: string
}

export const defaultWithIBeforeConstantSelectOptions: IBeforeConstantSelectOptions = {
  mix_relate_type: [],
  mix_relate_field_from: [],
  mix_assert_type: [],
  mix_assert_field_from: [],
  mix_assert_action: [],
  mix_location_type: [],
}

export interface IBeforeConstantSelectOptions {
  mix_relate_type: IDict[]
  mix_relate_field_from: IDict[]
  mix_assert_type: IDict[]
  mix_assert_field_from: IDict[]
  mix_assert_action: IDict[]
  mix_location_type: IDict[]
}


